package cn.socket.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * tcp获取数据
 */
public class TcpReceive {
    public static void main(String[] args) throws IOException {
            //创建服务器对象
            ServerSocket serverSocket = new ServerSocket(10000);
            //获取数据
            Socket accept = serverSocket.accept();
            InputStream inputStream = accept.getInputStream();
            //创建数据容器
            byte[] data = new byte[1024];
            int read = inputStream.read(data);
            //转字符串
            String str = new String(data, 0, data.length);
            System.out.println(str);
            serverSocket.close();

    }
}
